package top.archiesean.common.core.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;
import top.archiesean.common.core.enums.RespStatus;

import static top.archiesean.common.core.enums.RespStatus.FAIL;

/**
 * @author ArchieSean
 * @description 自定义异常
 * @date 2024-01-01 00:29
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class GlobalException extends RuntimeException{
    /**
     * 异常编码
     */
    private  Integer code;
    /**
     * 异常信息
     */
    private  String msg;

    public GlobalException(Integer code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public GlobalException(String msg) {
        super(msg);
        this.code = FAIL.getCode();
        this.msg = msg;
    }

    /**
     * 异常
     *
     * @param exception 异常
     */
    public GlobalException(RespStatus exception) {
        super(exception.getMsg());
        this.code = exception.getCode();
        this.msg = exception.getMsg();
    }
}
